from rest_framework import serializers

from news.models import News,  NewsCategory


# class NewsSerializer(serializers.ModelSerializer):
#     """新闻数据序列化器"""
#     class Meta:
# #model 指明要序列化的模型类
#         model = News
#         fields = ('id', 'name', 'price', 'default_image_url', 'comments')

class SlideNewsSerializer(serializers.ModelSerializer):
    """轮播图新闻数据序列化器"""
    class Meta:
#model 指明要序列化的模型类
        model = News
        fields = ('title', 'img_url')
        read_only_fields = ('title', 'img_url')

class TopNewsSerializer(serializers.ModelSerializer):
    """推荐新闻数据序列化器"""
    class Meta:
#model 指明要序列化的模型类
        model = News
        fields = ('title', 'create_time')
        read_only_fields = ('title', 'create_time')

class ImgNewsAlbumSerializer(serializers.ModelSerializer):
    """图片新闻数据序列化器"""

    class Meta:
        # model 指明要序列化的模型类
        model = News
        fields = ('title', 'create_time', 'img_url')
        read_only_fields = ('title', 'create_time', 'img_url')

class OneCategoryNewsAlbumSerializer(serializers.ModelSerializer):
    """图片新闻数据序列化器"""

    class Meta:
        # model 指明要序列化的模型类
        model = NewsCategory
        fields = ('id','title')
        read_only_fields = ('id','title')

# 备注序列化器优化，嵌套使用
class TwoCategoryNewsAlbumSerializer(serializers.ModelSerializer):
    """图片新闻数据序列化器"""

    class Meta:
        # model 指明要序列化的模型类
        model = News
        fields = ('title', 'create_time', 'img_url','zhaiyao')
        read_only_fields = ('title', 'create_time', 'img_url','zhaiyao')


